package com.yuhanginfo.modules.web.service;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yuhanginfo.common.persistence.Page;
import com.yuhanginfo.common.service.WebCrudService;
import com.yuhanginfo.common.utils.ReadProperties;
import com.yuhanginfo.modules.web.dao.NoticeDao;
import com.yuhanginfo.modules.web.dao.NoticeTypeDao;
import com.yuhanginfo.modules.web.entity.Notice;
import com.yuhanginfo.modules.web.entity.NoticeType;

/**
 * 公告信息Service
 * 
 * @author Y.j
 * @version 2017-11-10
 */
@Service
@Transactional(readOnly = true)
public class NoticeService extends WebCrudService<NoticeDao, Notice> {

	@Autowired
	private NoticeDao noticedao;
	@Autowired
	private NoticeTypeDao noticeTypedao;

	public Notice get(String id) {
		return super.get(id);
	}

	public List<Notice> findList(Notice notice) {
		return super.findList(notice);
	}

	public Page<Notice> findPage(Page<Notice> page, Notice notice){
		String pageSize = ReadProperties.ReadByName("page.webPageSize");
		page.setPageSize(Integer.parseInt(pageSize));
		return super.findPage(page, notice);
	}
	
	public List<NoticeType> findAllType(){
		return noticeTypedao.findAllType();
	}
	
	public List<Notice> findListByType(Map<String, String> params){
		List<Notice> noticeList=noticedao.findListByType(params);
		for(Notice n:noticeList) {
			SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
			n.setTime(formatter.format(n.getCreateDate()));
		}
		return noticeList;
	}
	
	public Notice findDetailById(Map<String, String> params) {
		Notice notice=noticedao.getDetailById(params);
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		notice.setTime(formatter.format(notice.getCreateDate()));
		return notice;
	}

}
